import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service


class MyTestCaseFireFox(unittest.TestCase):
    driver = None

    @classmethod
    def setUpClass(cls) -> None:
        # 注册 驱动打开的位置
        service = Service(executable_path="../../dirver_exe/geckodriver.exe")
        # 打开浏览器  driver 代表 浏览器对象
        cls.driver = webdriver.Firefox(service=service)

    def test_cookies(self):
        """获取网页中的  Cookies 值"""
        self.driver.get("https://www.jd.com/")
        # 获取 Cookies 信息
        cookies = self.driver.get_cookies()
        print(cookies)

        for item in cookies:
            print(item)

        self.driver.add_cookie({'name': 'hanamaki', 'value': '123456'})
        cookies = self.driver.get_cookies()
        print(cookies)

        for item in cookies:
            print(item)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.driver.close()  # 只会关闭一个标签页
        # cls.driver.quit()  # 直接退出浏览器 并且关闭所有的标签页


if __name__ == '__main__':
    unittest.main()
